package com.xbongbong.workflow.config;

import com.xbongbong.workflow.service.strategy.node.WorkflowNodeStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 节点策略的config
 * @author 魏荣杰
 * @date 2021/5/10 15:23
 * @since
 * @version
 */
@Configuration
public class WorkflowNodeStrategyConfig {


    @Autowired
    private Map<String, WorkflowNodeStrategy> workflowNodeStrategyMap;

    @Bean("workflowNodeStrategyMap")
    public Map<String, WorkflowNodeStrategy> initWorkflowNodeStrategyMap() {
        return workflowNodeStrategyMap.values().stream().filter(t -> Objects.nonNull(t.type())).collect(Collectors.toMap(WorkflowNodeStrategy::type, t -> t));
    }
}
